import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from "@dfeidao/atom-web/msg/nodejs";
import error from '@dfeidao/atom-web/msgbox/error';
import success from '@dfeidao/atom-web/msgbox/success';
import { md5 } from '@dfeidao/atom-web/str/md5';
import a015 from './a015';

interface Aa {
	_id: string;
	password: string;
}

export default async function a005(fd: IFeidaoAiBrowserComponent) {
	// 重置
	const input = fd.data.node.querySelectorAll('[data-feidao-name="list_checkbox"]:checked');
	// console.log("====" + input.length);
	if (input.length === 0) {
		error('请选择选要重置的用户');
		return;
	} else {
		const wk = new Array();
		Array.from(input).forEach((ipt: HTMLInputElement) => {
			const obj = {} as Aa;
			const id = ipt.getAttribute('data-feidao-id');
			const ucode = ipt.getAttribute('data-feidao-usercode');
			const pwd = md5(ucode + '111111');
			obj._id = id;
			obj.password = pwd;
			wk.push(obj);
		});
		const query = {
			wk
		};

		const del_res = await nodejs('consumer/zj-000001/s003', query);
		if (del_res === 'success') {
			success('重置成功');
			await a015(fd);
		} else {
			error('重置失败');
		}
	}
}
